local Lua__haijunwl = fk.CreateSkill({
  name = "Lua__haijunwl",
  frequency = Skill.Limited,
    tags = {Skill.Limited}
})

Fk:loadTranslationTable{
  ["Lua__haijunwl"] = "海军未来",
  ["$Lua__haijunwl1"] = "你们是正义的未来。",
  [":Lua__haijunwl"] = "限定技，你即将死亡时，你可选择一名已死亡的角色令其复活并将其势力与阵营调整为与你相同且获得技能拳骨流星。",
  ["#Lua__haijunwl-ask"] = "请选择一名已死亡的角色，令其复活并获得技能拳骨流星",
}

Lua__haijunwl:addEffect(fk.Death, {
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if target == player and player:hasSkill(Lua__haijunwl.name,false,true) then 
        return player:usedSkillTimes(Lua__haijunwl.name, Player.HistoryGame) == 0 and #table.map(table.filter(room.players, function(p) return p.dead end), function(p) return "seat#" .. tostring(p.seat) end) > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = table.map(table.filter(room.players, function(p) return p.dead end), function(p) return "seat#" .. tostring(p.seat) end)
    table.insert(tos,"Cancel")
      if #tos > 0 then
        local targets = room:askToChoice(player, {choices = tos, skill_name = Lua__haijunwl.name, prompt = "#Lua__haijunwl-ask"})
        if target ~= "Cancel" then
            event:setCostData(self, {choice = targets} )
            return true
        end
      end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = tonumber(string.sub(event:getCostData(self).choice, 6))
    for _, p in ipairs(room.players) do
        if p.seat == to then
            room:revivePlayer(p, true)
            room:broadcastProperty(p, player.role)

            room:setPlayerProperty(p, "role", player.role)
            room:setPlayerProperty(p, "kingdom", player.kingdom)
            room:notifyProperty(p, p, "role")
            room:notifyProperty(p, p, "kingdom")
            room:broadcastProperty(p, "role")
            room:broadcastProperty(p, "kingdom")
            if not p:hasSkill("Lua__quangulx") then
                room:handleAddLoseSkills(p, "Lua__quangulx")
            end
            break
        end
    end

  end,
})

return Lua__haijunwl 